<template>
  <div class="container">
    <div class="c-button">
      <el-button @click="add" class="button">新增公告</el-button>
      <el-input
        :style="{width: '200px',marginLeft: '10px'}"
        @keyup.enter.native="handleSearch"
        placeholder="请输入内容"
        suffix-icon="el-icon-zoom-in"
        v-model="input1"
      ></el-input>
    </div>
    <div class="c-form">
      <el-table
        :data="listData"
        style="width: 100%"
        :header-cell-style="{color: 'white', backgroundColor: '#267fc2', textAlign: 'center'}"
        :cell-style="{textAlign: 'center'}"
      >
        <el-table-column prop="title" label="标题" width="400"></el-table-column>
        <el-table-column prop="content" label="内容" width="500"></el-table-column>
        <el-table-column prop="created_at" label="时间" width="500"></el-table-column>
      </el-table>
      <div class="c-page">
        <el-pagination
          @current-change="handleCurrentChange"
          background
          layout="prev, pager, next"
          :total="page.total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>

<style lang="less" scope>
.container {
  position: relative;
  height: 100%;
}
.c-button {
  position: absolute;
  top: 50px;
  left: 150px;
}
.button {
  background-color: #267fc2;
  color: white;
}
.c-form {
  position: absolute;
  top: 120px;
  left: 150px;
}
.c-page {
  margin-top: 20px;
  display: flex;
  justify-content: center;
}
</style>

<script>
import RemoteData from "./mixins/RemoteData";
export default {
  mixins: [
    RemoteData({
      listData: "Admin/getAllSendNotices"
    })
  ],
  data() {
    return {
      input1: ""
    };
  },
  methods: {
    add() {
      this.$router.push({ name: "addMessage" });
    },
    goBack() {
      console.log("hah");
    },
    handleSearch() {
      this.$http
        .post("Admin/searchNotice", {
          params: {
            department_name: this.searchValue
          }
        })
        .then(res => {
          console.log(res.data.data);
          let searchData = res.data.data;
          this.updateData(searchData);
        });
    },
    handleCurrentChange(val) {
      this.$http
        .get("http://duty.myxy99.cn/api/Admin/getAllSendNotices?page=" + val)
        .then(res => {
          let pageData = res.data.data;
          this.updateData(pageData);
        });
    }
  }
};
</script>